#ifndef _TEMPLATES_H
#define _TEMPLATES_H

#include "../includes.h"

//{ ********** sprite base class **********
class cSprite
{
    public:
        // basic sprite variables
        std::string image;
        unsigned short imageID, spriteID;
        float X, Y, angle, speed;
        short midX, midY;
        bool hidden;
        // copy is mutable, so that when the const version of the class is passed to copy constructor, copy can be changed
        mutable bool copy;

        // basic sprite functions
        virtual bool onScreen(void);
        virtual bool hit(void);
        virtual void update(void);
};

bool cSprite::onScreen(void)
{
    // check if sprite exists and can be seen
    return (
            dbIsSprite(spriteID) &&
            X + dbImageWidth(imageID) * 1.5 >= 0 && X - dbImageWidth(imageID) * 1.5 <= dbScreenWidth() &&
            Y + dbImageHeight(imageID) * 1.5 >= 0 && Y - dbImageHeight(imageID) * 1.5 <= dbScreenHeight() &&
            !hidden );
}

bool cSprite::hit(void)
{
    dbHideSprite(spriteID); hidden = true;
    return false;
}

void cSprite::update(void)
{
    // if sprite doesn't exist or isn't visible, then return without doing anything
    if (!onScreen())
        return;

    // update X and Y locations to the correct value, based on the sprite's angle
    X += timerBased(speed * dbCos(angle + 90.0f));
    Y += timerBased(speed * dbSin(90.0f - angle));

    // render the sprite to that area
    dbSprite(spriteID, (int)X, (int)Y, imageID);

    return;
}

//} ********** sprite base class **********

#endif
